import {
    chooseAddress,
    showModal
} from '../../utils/asyncWx.js';
import regeneratorRuntime from '../../lib/runtime/runtime';
Page({
    data: {
        address: {},
        cart: [],
        allchecked: false,
        totalprice: 0,
        totalnum : 0
    },
    onShow() {
        /* 获取缓存中的数据 */
        const address = wx.getStorageSync('address');
        /* 获取缓存中的购物车数据 */
        let cart = wx.getStorageSync('cart') || []
        /* 过滤后的缓存数组 */
        cart=cart.filter(v=>v.checked);
        let totalprice = 0;
        let totalnum = 0;
        cart.forEach(v => {
            if (v.checked) {
                totalprice += v.num * v.goods_price;
                totalnum += v.num;
            }
        })
        /* 重新设置回data和缓存中 */
        this.setData({
            cart,totalprice,totalnum,address
        })
    },
    /* 点击支付 */
    handleauth(){
        wx.navigateTo({
          url: '/pages/auth/auth',
        })
    }
})